package utils;

import java.io.File;

public class DeleteVisitor implements NodeVisitor {

	public void visit(FileResources fr,File f) {
		delete(f);
	}
	
	public void delete(File file){
		//check if directory
		if(file.isDirectory()){
			//if directory is empty
			if(file.list().length == 0){
				file.delete();
			}
			//directory isn't empty
			else{
				//list all the directory contents
				String files[] = file.list();

				for (String temp : files) {
					//construct the file structure
					File fileDelete = new File(file, temp);

					//recursive delete
					delete(fileDelete);
				}
			}
		}
		//if it is a file
		else{
			file.delete();
		}
	}

	public void visit(FileResources fr, File f, File path) {}

	

}
